Allow to distinguish out of gas from other traps#4883
Conversation
|
It looks like @athei hasn't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io Once you've signed, please reply to this thread with Many thanks, Parity Technologies CLA Bot |
|
[clabot:check] |
|
It looks like @athei signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
pepyakin
left a comment
There was a problem hiding this comment.
Good start! I have only a few nits.
frame/contracts/src/wasm/runtime.rs
Outdated
| // - amount: How much gas is used. | ||
| gas(ctx, amount: u32) => { | ||
| charge_gas(&mut ctx.gas_meter, ctx.schedule, RuntimeToken::Explicit(amount))?; | ||
| charge_gas(&mut ctx.gas_meter, ctx.schedule, &mut ctx.special_trap, RuntimeToken::Explicit(amount))?; |
There was a problem hiding this comment.
This (an a few other) line exceeds the soft limit of 100. It would be great if we wrapped this line, like
charge_gas(
&mut ctx.gas_meter,
ctx.schedule,
&mut ctx.special_trap,
RuntimeToken::Explicit(amount)
)?;There was a problem hiding this comment.
I will look into the overlong lines.
There was a problem hiding this comment.
Removed the long lines I added / mofified.
| enum SpecialTrap { | ||
| /// Signals that trap was generated in response to call `ext_return` host function. | ||
| Return(Vec<u8>), | ||
| OutOfGas, |
There was a problem hiding this comment.
Would be useful to leave some words about this variant.
|
Any idea about the Open Issues part in my PR description? |
|
Ah yeah sorry. Yes, since you change the runtime behavior you need to bump the spec version as well. Otherwise, clients with older native runtime compiled in will execute that stale code rather than the wasm version under some circumstances. The second concern is valid, but I believe we cannot do anything with it atm. |
I guess the change would be to the javascript? I do not even see the extrinsic error on the node console. Is this intended or do I change the loglevel? The only way that I see that the change is working is that the test succeeds. |
|
I think yeah you need to change the log level, try |
0ccaf41 to
943697a
Compare
943697a to
eb7791c
Compare
eb7791c to
8b5df5c
Compare
|
This fixes #2584 |
When a contract encounters a runtime error a wasm trap is
triggered and the execution is halted. Currently, no matter
what was the cause for the trap it is always reported as:
DispatchError::Other("contract trapped during execution").
However, the trap that is triggered if a contract exhausts
its gas budget is particulary interesting. Therefore we add
a seperate error message for this cause:
DispatchError::Other("ran out of gas during contract execution").
A test is added hat executes a contract that never terminates.
Therefore it always exhausts is gas budget.
Remove overlong lines.
ee7ec70 to
5a99dbe
Compare
Rename Contract to Contracts
* contracts: Allow to distinguish out of gas from other traps
When a contract encounters a runtime error a wasm trap is
triggered and the execution is halted. Currently, no matter
what was the cause for the trap it is always reported as:
DispatchError::Other("contract trapped during execution").
However, the trap that is triggered if a contract exhausts
its gas budget is particulary interesting. Therefore we add
a seperate error message for this cause:
DispatchError::Other("ran out of gas during contract execution").
A test is added hat executes a contract that never terminates.
Therefore it always exhausts is gas budget.
* fixup! contracts: Allow to distinguish out of gas from other traps
Remove overlong lines.
* fixup! contracts: Allow to distinguish out of gas from other traps
Rename Contract to Contracts
Description
When a contract encounters a runtime error a wasm trap is
triggered and the execution is halted. Currently, no matter
what was the cause for the trap it is always reported as:
DispatchError::Other("contract trapped during execution").
However, the trap that is triggered if a contract exhausts
its gas budget is particulary interesting. Therefore we add
a seperate error message for this cause:
DispatchError::Other("ran out of gas during contract execution").
A test is added hat executes a contract that never terminates.
Therefore it always exhausts is gas budget.
fixes #2584
Open Issues
I am not sure whether to bumpimpl_versionorspec_version.spec_version should be bumped
The field of theOthererror variant (the error string) seems not to be passed through to the PolkadotAppsUI which renders this improvement rather unsatisfying:This is OK for now